package com.ews.onlineexchange.util;

import javax.inject.Named;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

@Named
@javax.enterprise.context.ApplicationScoped
public class Config {

	public static String getRegion(){
		String region = "dev";
		if(System.getenv("region") != null)region = System.getenv("region");
		return region;
	}
	public static String getPropName(){
		return 	"config-"+getRegion()+".properties";
	}
	public String getProperty(String key) {
		PropertiesConfiguration cfg;

		try {
			cfg = new PropertiesConfiguration(getPropName());
			return cfg.getString(key);
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}		
		return null;
	}
	
	public static String getStaticProperty( String key ) {
		PropertiesConfiguration cfg;
		try {
			cfg = new PropertiesConfiguration( getPropName() );
			return cfg.getString( key );
		} catch ( ConfigurationException e ) {
			e.printStackTrace();
		}
		return null;
	}
	private final static String PREFIX = "com.ews.onlineExchange.";
	public static String getPropertyIncludePrefix( String key ) {
		PropertiesConfiguration cfg;
		try {
			cfg = new PropertiesConfiguration( getPropName() );
			return cfg.getString( PREFIX + key );
		} catch ( ConfigurationException e ) {
			e.printStackTrace();
		}
		return null;
	}

	
}
